package ro.isdc.vms.misc.domain;

import java.util.Date;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;

/**
 * Abstract entity base class. An entity is a class whose objects have identity and which
 * are persisted in a separate table associated to that class.
 * 
 * @author Andrei Chirila / ISDC! Romania
 * @version 1.0.0
 * @date Jul 20, 2009
 */
public abstract class Entity extends DataObject {
		
	/**
	 * Unique internal entity identifier (primary key for non-version 
	 * entities).
	 */
	private long entityId = -1;
	
	/**
	 * Uniquely identifies the current version of the business entity. This is
	 * also needed for all business entities, for database locking/concurrency
	 * checking purposes.
	 */
	private int versionNo;
	/**
	 * The user id of the creator of this entity.
	 */
	private long createdBy = -1;

	/**
	 * Date/time when the entity/version was created.
	 */
	private Date creationTimestamp;

	/**
	 * Date/time when the entity was deleted.
	 */
	private Date deletionTimestamp;

	/**
	 * The user id for the last change/version of this entity.
	 */
	private long lastUpdatedBy = -1;

	/**
	 * Date/time of the last change/version creation.
	 */
	private Date lastUpdateTimestamp;

	/**
	 * Determines if/when the entity was last deemed old/a candidate for
	 * removal, and flagged accordingly.
	 */
	private Date oldFlaggedTimestamp;

	/**
	 * @return the entityId
	 */
	public long getEntityId() {
		return entityId;
	}

	/**
	 * @param entityId the entityId to set
	 */
	public void setEntityId(long entityId) {
		this.entityId = entityId;
	}

	/**
	 * @return the versionNo
	 */
	public int getVersionNo() {
		return versionNo;
	}

	/**
	 * @param versionNo the versionNo to set
	 */
	public void setVersionNo(int versionNo) {
		this.versionNo = versionNo;
	}

	/**
	 * @return the createdBy
	 */
	public long getCreatedBy() {
		return createdBy;
	}

	/**
	 * @param createdBy the createdBy to set
	 */
	public void setCreatedBy(long createdBy) {
		this.createdBy = createdBy;
	}

	/**
	 * @return the creationTimestamp
	 */
	public Date getCreationTimestamp() {
		return creationTimestamp;
	}

	/**
	 * @param creationTimestamp the creationTimestamp to set
	 */
	public void setCreationTimestamp(Date creationTimestamp) {
		this.creationTimestamp = creationTimestamp;
	}

	/**
	 * @return the deletionTimestamp
	 */
	public Date getDeletionTimestamp() {
		return deletionTimestamp;
	}

	/**
	 * @param deletionTimestamp the deletionTimestamp to set
	 */
	public void setDeletionTimestamp(Date deletionTimestamp) {
		this.deletionTimestamp = deletionTimestamp;
	}

	/**
	 * @return the lastUpdatedBy
	 */
	public long getLastUpdatedBy() {
		return lastUpdatedBy;
	}

	/**
	 * @param lastUpdatedBy the lastUpdatedBy to set
	 */
	public void setLastUpdatedBy(long lastUpdatedBy) {
		this.lastUpdatedBy = lastUpdatedBy;
	}

	/**
	 * @return the lastUpdateTimestamp
	 */
	public Date getLastUpdateTimestamp() {
		return lastUpdateTimestamp;
	}

	/**
	 * @param lastUpdateTimestamp the lastUpdateTimestamp to set
	 */
	public void setLastUpdateTimestamp(Date lastUpdateTimestamp) {
		this.lastUpdateTimestamp = lastUpdateTimestamp;
	}

	/**
	 * @return the oldFlaggedTimestamp
	 */
	public Date getOldFlaggedTimestamp() {
		return oldFlaggedTimestamp;
	}

	/**
	 * @param oldFlaggedTimestamp the oldFlaggedTimestamp to set
	 */
	public void setOldFlaggedTimestamp(Date oldFlaggedTimestamp) {
		this.oldFlaggedTimestamp = oldFlaggedTimestamp;
	}

	/**
	 * @see java.lang.Object#equals(Object)
	 */
	public boolean equals(final Object object) {
		if (object == this) {
			return true;
		}
		if (!(object instanceof Entity)) {
			return false;
		}
		Entity rhs = (Entity) object;
		return new EqualsBuilder().append(this.entityId,
				rhs.entityId).isEquals();
	}

	/**
	 * @see java.lang.Object#hashCode()
	 */
	public int hashCode() {
		return new HashCodeBuilder(-2103341447, 1374325971).append(
				this.entityId).toHashCode();
	}
	
}
